package com.xiao.xin.core.service.Impl;

import com.xiao.xin.core.service.WsNoticeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Slf4j
@Service
public class WsNoticeServiceImpl implements WsNoticeService {

    public final static String COMFYUI_QUEUE_TOPIC = "/topic/messages";

    @Autowired
    SimpMessagingTemplate simpMessagingTemplate;

    /**
     * 发送给对应用户
     * @param wsClientId
     * @param message
     */
    public void sendToUser(String wsClientId, String message){
        log.info("用户:{} \n 数据:{}",wsClientId,message);
        simpMessagingTemplate.convertAndSendToUser(wsClientId, COMFYUI_QUEUE_TOPIC, message);
    }

    /**
     * 发送给所有用户
     * @param message
     */
    public void sendToAll(String message){
        log.info("所有用户数据:{}",message);
        simpMessagingTemplate.convertAndSend(COMFYUI_QUEUE_TOPIC, message);
    }
}
